import 'package:json_annotation/json_annotation.dart';

part 'message.g.dart';

@JsonSerializable()
class MessageModel {
  String addTime;

  String title;

  String? content;

  String? img;

  String? url;

  @JsonKey(unknownEnumValue: MessageEnum.systemMessage)
  MessageEnum type;

  MessageModel(
      {required this.title,
      this.content,
      this.type = MessageEnum.systemMessage,
      required this.addTime,
      this.img,
      this.url});

  factory MessageModel.fromJson(Map<String, dynamic> json) => _$MessageModelFromJson(json);

  Map<String, dynamic> toJson() => _$MessageModelToJson(this);

  @override
  String toString() {
    return toJson().toString();
  }
}

enum MessageEnum {
  systemMessage(1, '系统'),
  orderMessage(2, '订单'),
  activityMessage(3, '活动');

  final int type;
  final String text;

  const MessageEnum(this.type, this.text);
}
